<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>商品管理</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/css/bootstrap.min.css" />
<script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
</head>
<body>
	<!-- 头部信息 -->
	<jsp:include page="header.jsp"></jsp:include>
	
	<!-- 商品搜索区 -->
	<jsp:include page="product-search.jsp"></jsp:include>
	
	<!-- 内容区域 -->
	<div class="container-fluid">
		<div class="col-xs-8"
			style="border: 1px solid gray; height: 500px; border-radius: 8px;">
			<h4>商品列表</h4>
			<table class="table">
				<thead>
					<tr>
						<th>商品编号</th>
						<th>商品名称</th>
						<th>类别</th>
						<th>库存</th>
						<th>单价(元)</th>
						<th colspan="2" style="width: 20%;">操作</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${pageInfo.list}" var="product">
						<tr>
							<td>${product.productNum}</td>
							<td>${product.productName }</td>
							<td>${product.category.categoryName}</td>
							<td>${product.stock}</td>
							<td>${product.price }</td>
							<td><button type="button" class="btn btn-primary" onclick="location.href='${pageContext.request.contextPath}/product/findById.do?productId=${product.productId}'">详情</button></td>
							<td><a class="btn btn-danger"
								href='${pageContext.request.contextPath}/product/delete.do?productId=${product.productId}'>删除</a></td>
						</tr>
					</c:forEach>

				</tbody>
			</table>
			
				<!-- 分页 -->
			<div class="col-md-offset-5">
				<nav aria-label="Page navigation">
				<ul class="pagination">
					<c:if test="${pageInfo.pageNum==1}">
						<li class="disabled"><a href="#" aria-label="Previous"> <span
							aria-hidden="true">&laquo;</span>
					</a></li>
					</c:if>
					
					<c:if test="${pageInfo.pageNum!=1}">
						<li><a href="${pageContext.request.contextPath}/product/findAll.do?pageNum=${pageInfo.pageNum-1}&condition=${condition}" aria-label="Previous"> <span
							aria-hidden="true">&laquo;</span>
					</a></li>
					</c:if>

					<c:forEach begin="1" end="${pageInfo.pages}" var="i">
						<c:if test="${pageInfo.pageNum!=i}">
							<li><a
								href="${pageContext.request.contextPath}/product/findAll.do?pageNum=${i}&condition=${condition}">${i}</a></li>
						</c:if>
						<c:if test="${pageInfo.pageNum==i}">
							<li class="active"><a
								href="${pageContext.request.contextPath}/product/findAll.do?pageNum=${i}&condition=${condition}">${i}</a></li>
						</c:if>
					</c:forEach>
					
					<c:if test="${pageInfo.pageNum==pageInfo.pages}">
						<li class="disabled"><a aria-label="Next"> <span
							aria-hidden="true">&raquo;</span>
					</a></li>
					</c:if>
					
					<c:if test="${pageInfo.pageNum!=pageInfo.pages}">
						<li><a href="${pageContext.request.contextPath}/product/findAll.do?pageNum=${pageInfo.pageNum+1}&condition=${condition}" aria-label="Next"> <span
							aria-hidden="true">&raquo;</span>
					</a></li>
					</c:if>
				</ul>
				 <h4> 共${pageInfo.pages}条记录，共${pageInfo.total}页</h4>
			</nav>
			</div>
			

		</div>

		<div class="col-xs-1"></div>
		
		<jsp:include page="product-add.jsp"></jsp:include>
	</div>
</body>
</html>
